<?php
namespace app\common\model;

use think\model\concern\SoftDelete;

class Order extends Base
{
    use SoftDelete;

    protected $name = 'order';
    protected $deleteTime = 'delete_time';

    public function getOrderList($where)
    {
        return $this->alias('o')
            ->join('product p', 'o.product_id = p.id')
            ->where($where)
            ->field('o.id, p.name, p.show_img, o.total, o.sku_name, o.status')
            ->select();
    }

    public function getStatusAttr($val)
    {
        $status = [1 => '待付款', 2 => '已付款', 3 => '已发货', 4 => '已完成', 5 => '已取消'];
        return $status[$val];
    }

    public function getPayTimeAttr($val)
    {
        if(!$val){
            return '-';
        }

        return date('Y-m-d H:i:s', $val);
    }

    public function getSendTimeAttr($val)
    {
        if(!$val){
            return '-';
        }

        return date('Y-m-d H:i:s', $val);
    }

    public function getFinishTimeAttr($val)
    {
        if(!$val){
            return '-';
        }

        return date('Y-m-d H:i:s', $val);
    }
}